package org.wutopia.labcloud.domain.uaa.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.wutopia.labcloud.domain.uaa.controller.vo.input.UserProductCartAddInputVO;
import org.wutopia.labcloud.domain.uaa.controller.vo.input.UserProductCartDeleteInputVO;
import org.wutopia.labcloud.domain.uaa.controller.vo.output.UserCartGetListOutputVO;
import org.wutopia.labcloud.domain.uaa.service.UserProductCartService;
import org.wutopia.labcloud.library.common.base.CodedMessage;
import org.wutopia.labcloud.library.common.base.CommonResponse;

@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("/user/product/cart")
public class UserProductCartController {

    private UserProductCartService userProductCartService;

    @GetMapping("/list")
    public ResponseEntity<CodedMessage<UserCartGetListOutputVO>> getList(@RequestParam Long userId) {

        UserCartGetListOutputVO vo = userProductCartService.getList(userId);

        return CommonResponse.successWithData(vo);
    }

    @PostMapping("/add")
    public ResponseEntity<CodedMessage<String>> add(@RequestBody UserProductCartAddInputVO vo)  {

        userProductCartService.add(vo);

        return CommonResponse.success();
    }

    @PostMapping("/delete")
    public ResponseEntity<CodedMessage<String>> delete(@RequestBody UserProductCartDeleteInputVO vo)  {

        userProductCartService.delete(vo);

        return CommonResponse.success();
    }
}
